<?php require_once("../includes/preload.php"); if(!isset($_SESSION)){session_start();}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name='content-type' content='text/html' />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $config["text"]["name"]; ?> &middot; Control Panel</title>
</head>
<link rel='stylesheet' href='../design/styles/setup/style.css' type='text/css' />
<link rel='stylesheet' href='../scripts/editor_style.css' type='text/css' />
<script src='../scripts/editor.js' type='text/javascript'></script>
<body>
<div class='container'>
	<div class='header'>
    	<h1>Control Panel</h1>
    </div>
	<div class='navigation'>
		<a href='index.php?page=c_home' class='nav' title='CP Home'>Home</a>
        <a href='index.php?page=c_post' class='nav' title='Post Management'>Posts</a>
        <a href='index.php?page=c_style' class='nav' title='Style Management'>Style</a>
        <a href='index.php?page=c_adv' class='nav' title='Advanced Features'>Advanced</a>
	</div>
	<div class='content'>
    	<?php
		if(!isset($_SESSION['user']) && !isset($_GET['act']))
		{
			echo "<h1>Log in to continue...</h1><p>You need to log in to be able to access the control panel
			<form action='index.php?act=login' method='post'>
			<fieldset><legend>Log In</legend>
			<input class='text-box' type='text' name='uname' /><label for='uname'>User Name</label><br>
			<input class='text-box' type='text' name='pass' /><label for='pass'>Password</label><br>
			<input type='submit' name='submit' value='Log In'></fieldset></form>";
		}
		elseif($_GET['act'] == 'login')
		{
			$a_uname = $config["admin"]["admin-name"];
			$a_pass = $config["admin"]["password"];
			$p_uname = $_POST["uname"];
			$p_pass = md5($_POST["pass"]);
			if($a_uname == $p_uname) {
				if($a_pass == $p_pass) {
					$_SESSION['user'] = $p_uname;
					echo "<script>location.href='index.php?p=c_home'</script>";
				} else {
					echo "Incorrect password";
				}
			} else {
				echo "Incorrect Username";
			}
		}
		else
		{
			$page = $_GET['page'];
			switch($page)
			{
				default: include("modules/c_home.php");break;
				case"c_home":include("modules/c_home.php");break;
				case"c_post_add":include("modules/c_post_add.php");break;
			}
		}
		?>
    </div>
    <div class='footer'>
    <p><?php echo $config["text"]["footer"]; ?></p>
    </div>
</div>
</body>
</html>
